# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=text-show
pkgname=haskell-text-show
pkgver=3.10.2
pkgrel=25
pkgdesc="Efficient conversion of values into Text"
url="https://github.com/RyanGlScott/text-show"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-base-compat-batteries' 'haskell-bifunctors' 'haskell-generic-deriving'
         'haskell-th-abstraction' 'haskell-th-lift' 'haskell-transformers-compat')
makedepends=('ghc' 'uusi' 'haskell-base-orphans' 'haskell-deriving-compat' 'haskell-hspec'
             'haskell-quickcheck' 'haskell-quickcheck-instances')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz
        quickcheck-2.14.3.patch)
sha512sums=('64ab2db95302954e4624192394cc29c355d2681b043cc0bd3ad88080e5f2f5a5f93c15e24f9c861f41c16d440ac227855292d3ab8b8d2da9275b9c3b6bb296dd'
            '068afc92665fcb3bde53aae0c0a6e6e8f7e8b2d85c75ea27aa54101ed4622b5431bf38eeb3ee897a68f02d5872a7e797a3ab28f8471cbe60087cfec3a0986f2e')

prepare() {
    cd $_hkgname-$pkgver
    patch -Np1 -i ../quickcheck-2.14.3.patch
    uusi -d bytestring-builder $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
